package jflowmap.views.heatmap;

import java.awt.geom.Rectangle2D;

import jflowmap.util.piccolo.PBoxLayoutNode;
import jflowmap.util.piccolo.PNodes;
import jflowmap.views.Disposable;
import edu.umd.cs.piccolo.PCamera;
import edu.umd.cs.piccolo.PLayer;
import edu.umd.cs.piccolo.util.PBounds;

public abstract class AbstractLayer extends PLayer implements Disposable {
	private final PCamera camera;
	private final PBoxLayoutNode layerMenu = new PBoxLayoutNode(PBoxLayoutNode.Axis.X, 2);
	
	private double relativeWidth;
	
	public AbstractLayer(double relativeWidth) {
		this.camera = new PCamera();
		this.camera.addLayer(this);
		this.relativeWidth = relativeWidth;
		
		this.camera.addChild(layerMenu);
	}
	
	public final PCamera getCamera() {
		return camera;
	}
	
	public final PBoxLayoutNode getLayerMenuPanel() {
		return layerMenu;
	}
	
	public void update() {
		this.layerMenu.moveToFront();
	}

	public final void fitInView (PBounds bounds) {		
		camera.setViewBounds(bounds);
		updateMenuPosition();
	}
	
	public final void updateMenuPosition() {
		Rectangle2D cb = layerMenu.parentToLocal(camera.getBounds());
		PNodes.moveTo(layerMenu, cb.getX() + cb.getWidth()/2 - layerMenu.getWidth()/2, cb.getY());
	}
	
	public void fitChildrenInView() {
		fitInView(this.getFullBounds());
	}
	
	final void setRelativeWidth (double relativeWidth) {
		this.relativeWidth = relativeWidth;
	}
	
	final double getRelativeWidth () {
		return this.relativeWidth;
	}
	

	
}
